package com.kunbo.cn.controller.base;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.kunbo.cn.dao.system.BusinessCodeDao;
import com.kunbo.cn.entity.system.BusinessCode;
import com.kunbo.cn.service.system.BusinessCodeService;
import com.kunbo.cn.util.date.SDate;

@Component
public class TimerTask {
	@Autowired
	private BusinessCodeDao businessCodeDao;
	@Autowired
	private BusinessCodeService businessCodeService;
	/**
	 * 每天凌晨执行一次
	 */
	@Scheduled(cron = "0 0 0 * * ?")
	public void scheduledTask(){
		System.out.println("凌晨到了，我该执行某些动作了"+new Date());
		List<BusinessCode> list = (List<BusinessCode>) businessCodeDao.findAll();
		if(list.size()==0) {
			list.add(new BusinessCode("CGDD",1,SDate.getSystemDateYMDToString()));
			list.add(new BusinessCode("CGYD",1,SDate.getSystemDateYMDToString()));
			list.add(new BusinessCode("DHTZD",1,SDate.getSystemDateYMDToString()));
			list.add(new BusinessCode("CGBD",1,SDate.getSystemDateYMDToString()));
			list.add(new BusinessCode("XSDD",1,SDate.getSystemDateYMDToString()));
			list.add(new BusinessCode("XSYD",1,SDate.getSystemDateYMDToString()));
			list.add(new BusinessCode("THTZD",1,SDate.getSystemDateYMDToString()));
			list.add(new BusinessCode("XSBD",1,SDate.getSystemDateYMDToString()));
			businessCodeDao.save(list);
		}else if(list.size()>0) {
			businessCodeService.updateNumberAndDate(1, SDate.getSystemDateYMDToString());
		}
		
		
	}
	
//  每分钟启动 
//	@Scheduled(cron = "0 0/1 * * * ?") 
//	public void timerToNow(){ 
//		
//	}



}
